package com.hydl.power.service.impl;

import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hydl.power.mapper.HaiwellAccountMapper;
import com.hydl.power.pojo.HaiwellAccount;
import com.hydl.power.pojo.HaiwellAccountExample;
import com.hydl.power.pojo.SysUser;
import com.hydl.power.service.HaiwellAccountService;
import com.hydl.power.service.SysUserService;
import com.hydl.power.utils.Resp;

/**
 * @author miss
 * @version V3.0
 * @since 2022/11/25 22:58
 */
@Service
public class HaiwellAccountServiceImpl implements HaiwellAccountService {

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private HaiwellAccountMapper haiwellAccountMapper;

    @Override
    public Resp getHaiwellAccountByToken(String token) {
        SysUser sysUser = sysUserService.getUserByToken(token);
        if (sysUser == null) {
            return Resp.fail("获取用户信息失败");
        }
        HaiwellAccountExample example = new HaiwellAccountExample();
        HaiwellAccountExample.Criteria criteria = example.createCriteria();
        criteria.andSysUserIdEqualTo(sysUser.getId());
        List<HaiwellAccount> haiwellAccountList = haiwellAccountMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(haiwellAccountList)) {
            return Resp.fail("获取海为用户信息失败");
        }
        return Resp.success(haiwellAccountList.get(0));

    }
}
